home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / exec / procure.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  3KB  |  103 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: procure.c,v 1.6 1996/10/24 15:50:53 aros Exp $
  4.     $Log: procure.c,v $
  5.     Revision 1.6  1996/10/24 15:50:53  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.5  1996/09/13 17:51:23  digulla
  9.     Use IPTR
  10.  
  11.     Revision 1.4  1996/08/13 13:56:05  digulla
  12.     Replaced AROS_LA by AROS_LHA
  13.     Replaced some AROS_LH*I by AROS_LH*
  14.     Sorted and added includes
  15.  
  16.     Revision 1.3  1996/08/01 17:41:15  digulla
  17.     Added standard header for all files
  18.  
  19.     Desc:
  20.     Lang: english
  21. */
  22. #include "exec_intern.h"
  23. #include "semaphores.h"
  24.  
  25. /*****************************************************************************
  26.  
  27.     NAME */
  28.     #include <exec/semaphores.h>
  29.     #include <clib/exec_protos.h>
  30.  
  31.     AROS_LH2(ULONG, Procure,
  32.  
  33. /*  SYNOPSIS */
  34.     AROS_LHA(struct SignalSemaphore  *, sigSem, A0),
  35.     AROS_LHA(struct SemaphoreMessage *, bidMsg, A1),
  36.  
  37. /*  LOCATION */
  38.     struct ExecBase *, SysBase, 90, Exec)
  39.  
  40. /*  FUNCTION
  41.     Tries to get a lock on a semaphore in an asynchronous manner.
  42.     If the semaphore is not free this function will not wait but
  43.     just post a request to the semaphore. As soon as the semaphore is
  44.     available the bisMsg will return and make you owner of the semaphore.
  45.  
  46.     INPUTS
  47.     sigSem - pointer to semaphore structure
  48.     bidMsg - pointer to a struct SemaphoreMessage. This should lie in
  49.          public or at least shared memory.
  50.  
  51.     RESULT
  52.     Principly none. Don't know. Just ignore it.
  53.  
  54.     NOTES
  55.     Locks obtained with Procure() must be released with Vacate().
  56.  
  57.     EXAMPLE
  58.  
  59.     BUGS
  60.  
  61.     SEE ALSO
  62.     Vacate()
  63.  
  64.     INTERNALS
  65.  
  66.     HISTORY
  67.     29-10-95    digulla automatically created from
  68.                 exec_lib.fd and clib/exec_protos.h
  69.     22-01-96    fleischer implementation
  70.  
  71. *****************************************************************************/
  72. {
  73.     AROS_LIBFUNC_INIT
  74.     AROS_LIBBASE_EXT_DECL(struct ExecBase *,SysBase)
  75.  
  76.     /* Prepare semaphore message to be a sent message */
  77.     bidMsg->ssm_Message.mn_Length=sizeof(struct SemaphoreMessage);
  78.     bidMsg->ssm_Message.mn_Node.ln_Type=NT_MESSAGE;
  79.  
  80.     /* Arbitrate for the semaphore structure */
  81.     Forbid();
  82.  
  83.     /* Try to get the semaphore immediately. */
  84.     if((IPTR)(bidMsg->ssm_Message.mn_Node.ln_Name)==SM_SHARED?
  85.        AttemptSemaphoreShared(sigSem):AttemptSemaphore(sigSem))
  86.     {
  87.     /* Got it. Reply the message. */
  88.     bidMsg->ssm_Semaphore=sigSem;
  89.     ReplyMsg(&bidMsg->ssm_Message);
  90.     }
  91.     else
  92.     /* Couldn't get it. Add message to the semaphore's waiting queue. */
  93.     AddTail((struct List *)&sigSem->ss_WaitQueue,&bidMsg->ssm_Message.mn_Node);
  94.  
  95.     /* All done. */
  96.     Permit();
  97.  
  98.     /* Huh? */
  99.     return 0;
  100.     AROS_LIBFUNC_EXIT
  101. } /* Procure */
  102.  
  103.